package com.qishenyuan.competition.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qishenyuan.competition.annotation.TokenParam;
import com.qishenyuan.competition.common.PageResult;
import com.qishenyuan.competition.common.PageUtil;
import com.qishenyuan.competition.common.Response;
import com.qishenyuan.competition.dto.FindJobBriefReq;
import com.qishenyuan.competition.dto.FindJobTopicReq;
import com.qishenyuan.competition.service.FindJobService;
import com.qishenyuan.competition.vo.FindJobBriefResp;
import com.qishenyuan.competition.vo.FindJobResp;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 找工作帖子信息表 前端控制器
 * </p>
 *
 * @author qishenyuan
 * @since 2025-03-25
 */
@RestController
@RequestMapping("/findJob")
public class FindJobController {

    @Resource
    private FindJobService findJobService;

    @RequestMapping("/getFindJobList")
    public Response<? extends Map> getFindJobList(@RequestBody @Valid FindJobBriefReq findJobBriefReq){
        IPage<FindJobBriefResp> findJobList = findJobService.getFindJobList(findJobBriefReq);
        PageResult<FindJobBriefResp> pageResult = PageUtil.toPageResult(findJobList);
        return Response.ok(pageResult);
    }

    @GetMapping("/getFindJob/{id}")
    public Response<FindJobResp> getFindJob(@PathVariable Integer id){
        FindJobResp findJobResp = findJobService.getFindJob(id);
        if(findJobResp != null){
            return Response.ok(findJobResp);
        }else {
            return Response.failed("null");
        }
    }

    @RequestMapping("/createFindJobTopic")
    public Response<?> createFindJobTopic(@TokenParam String token, @RequestBody @Valid FindJobTopicReq findJobTopicReq){
        findJobService.createFindJobTopic(token, findJobTopicReq);
        return Response.ok();
    }
}
